package com.ruoyi.web.controller.systembasic;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.mes.systembasic.domain.SmesEmployee;
import com.ruoyi.mes.systembasic.service.ISmesEmployeeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesCustomer;
import com.ruoyi.mes.systembasic.service.ISmesCustomerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 客户管理Controller
 * 
 * @author yanqin
 * @date 2020-11-24
 */
@RestController
@RequestMapping("/systembasic/customer")
public class SmesCustomerController extends BaseController
{
    @Autowired
    private ISmesCustomerService smesCustomerService;

    @Autowired
    private ISmesEmployeeService smesEmployeeService;

    /**
     * 查询客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:customer:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesCustomer smesCustomer)
    {
        startPage();
        List<SmesCustomer> list = smesCustomerService.selectSmesCustomerList(smesCustomer);
        return getDataTable(list);
    }

    /**
     * 导出客户管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:customer:export')")
    @Log(title = "客户管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesCustomer smesCustomer)
    {
        List<SmesCustomer> list = smesCustomerService.selectSmesCustomerList(smesCustomer);
        ExcelUtil<SmesCustomer> util = new ExcelUtil<SmesCustomer>(SmesCustomer.class);
        return util.exportExcel(list, "customer");
    }

    /**
     * 获取客户管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:customer:query')")
    @GetMapping(value = "/{customerNo}")
    public AjaxResult getInfo(@PathVariable("customerNo") String customerNo)
    {

        AjaxResult ajax = AjaxResult.success();
        List<SmesEmployee> employees=smesEmployeeService.selectSmesEmployeeList(new SmesEmployee());
        ajax.put("employees",employees);
        if (StringUtils.isNotNull(customerNo))
        {
            ajax.put(AjaxResult.DATA_TAG, smesCustomerService.selectSmesCustomerById(customerNo));
        }
        return ajax;
    }

    /**
     * 新增客户管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:customer:add')")
    @Log(title = "客户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesCustomer smesCustomer)
    {
        return toAjax(smesCustomerService.insertSmesCustomer(smesCustomer));
    }

    /**
     * 修改客户管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:customer:edit')")
    @Log(title = "客户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesCustomer smesCustomer)
    {
        return toAjax(smesCustomerService.updateSmesCustomer(smesCustomer));
    }

    /**
     * 删除客户管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:customer:remove')")
    @Log(title = "客户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{customerNos}")
    public AjaxResult remove(@PathVariable String[] customerNos)
    {
        return toAjax(smesCustomerService.deleteSmesCustomerByIds(customerNos));
    }
}
